<template>
	<view class="page">
		<view class="workContent">
			<view class="handleBox"  v-for="(item,index) in handleArr" :key="index" :style="item.style?item.style:''">
				<view class="handleTitle">
					{{item.name | handleText}}
				</view>
				<view class="handleArr">
					<view class="handleItem" v-for="(item2,index2) in item.pageArr" :key="index2" @click="handleGoPage(item2.url,item2)">
						<view class="cover">
							<u-image shape="circle" :showLoading="true" :src="imgBaseUrl+item2.icon"  width="99rpx" height="99rpx"></u-image>
						</view>
						<text>{{item2.name | handleText}}</text>
					</view>
				</view>
			</view>
			<!-- <view class="handleBox"  v-for="(item,index) in handleArr" :key="index" :style="item.style?item.style:''">
				<view class="handleTitle">
					{{item.title}}
				</view>
				<view class="handleArr">
					<view class="handleItem" v-for="(item2,index2) in item.pageArr" :key="index2" @click="handleGoPage(item2.url)">
						<view class="cover">
							<u-image shape="circle" :showLoading="true" :src="item2.img" width="99rpx" height="99rpx"></u-image>
						</view>
						<text>{{item2.text}}</text>
					</view>
				</view>
			</view>
		 -->
		</view>
		
		<!-- <view class="leftRightRow" >
			<view class="leftRightItem">
				<view class="cover">
					<u-image :showLoading="true" :src="item2.img" width="99rpx" height="99rpx"></u-image>
				</view>
				<text>课程表</text>
			</view>
			<view class="leftRightItem">
				<view class="cover">
					<u-image :showLoading="true" :src="item2.img" width="99rpx" height="99rpx"></u-image>
				</view>
				<text>成绩</text>
			</view>
		</view> -->
		
	</view>
</template>

<!-- <script src="@/common/js/jweixin.js"></script> -->
<script>
	import {getPersonApi,getoaOpenInfoApi,sysAppletPermissionQueryByUserNameApi,getCodeIndexApi} from '@/common/api/commonApi/commonApi.js'
	import {getParentApi} from '@/common/api/commonApi/phoneApi.js'
	import base from '@/common/config'
	import {pageItem} from './data.js'
	let menuList = []
	export default {
		data() {
			return {
				teacherHandleArr:[
					{
						title: '考勤',
						pageArr:[
							{
								// img:'/static/images/work/teacherItem1.png',
								img: base.imgBaseUrl+'/images/work/teacherItem1.png',
								text: '学生请假',
								url: '/pages/componentsC/checkingIn/leaveRecord'
							},
							// {
							// 	img:'',
							// 	text: '学生请假记录',
							// 	url:''
							// },
							{
								img:  base.imgBaseUrl+'/images/work/teacherItem2.png',
								text: '个人刷卡记录',
								url: '/pages/componentsC/checkingIn/swipingCardRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem3.png',
								text: '个人补登',
								url:'/pages/componentsC/checkingIn/repairForm'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem4.png',
								text: '个人事件登记',
								url:'/pages/componentsC/checkingIn/eventRepairForm'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem5.png',
								text: '个人考勤明细',
								url:'/pages/componentsC/checkingIn/checkingInDetail'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem6.png',
								text: '个人考勤统计',
								url:'/pages/componentsC/checkingIn/checkingInTotal'
							},
						]
					},
					{
						title: '安全',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem7.png',
								text: '学生出入记录',
								url:'/pages/componentsC/safe/accessRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem8.png',
								text: '学生出入统计',
								url:'/pages/componentsC/safe/accessRecordTotal'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem9.png',
								text: '学生临时出入',
								url:'/pages/componentsC/safe/tempAccessRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem10.png',
								text: '学生轨迹',
								url:'/pages/componentsC/safe/studentTrack'
							},
							{
								img: base.imgBaseUrl+'/images/work/item8.png',
								text: '临时通行',
								// url:'/pages/componentsC/safe/tempForm'
								url:'/pages/componentsC/safe/tempStudentList'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem33.png',
								text: '校车接送',
								url:'/pages/componentsC/safe/busing'
							},
						]
					},
					{
						title: '消费',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem11.png',
								text: '充值',
								url:'/pages/componentsB/topupCard/topupCard'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem12.png',
								text: '充值记录',
								url: '/pages/componentsB/topupRecord/topupRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem13.png',
								text: '消费记录',
								url:'/pages/componentsB/consumeRecord/consumeRecord'
							},
						]
					},
					{
						title: '宿管',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem5.png',
								text: '考勤记录',
								url:'/pages/componentsC/dorm/attendanceRecord'
							},
							// {
							// 	img: base.imgBaseUrl+'/images/work/teacherItem6.png',
							// 	text: '考勤结果',
							// 	url:'/pages/componentsC/dorm/attendanceResult'
							// },
							{
								img: base.imgBaseUrl+'/images/work/teacherItem14.png',
								text: '归寝统计',
								url: '/pages/componentsC/dorm/bedtimeStatistics'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem15.png',
								text: '异常考勤记录',
								url:'/pages/componentsC/dorm/exceptionAttendance'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem16.png',
								text: '待核实异常',
								url:'/pages/componentsC/dorm/notVerifyException'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem17.png',
								text: '宿舍评分',
								// url:'/pages/componentsC/dorm/score'
								url:'/pages/componentsC/dorm/tempDormList'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem18.png',
								text: '宿舍评分记录',
								url:'/pages/componentsC/dorm/scoreRecord'
							},
						]
					},
					{
						title: '退餐退课',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem19.png',
								text: '退课查看',
								url: '/pages/componentsC/dropClass/dropClassList'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem20.png',
								text: '退餐查看',
								url:'/pages/componentsC/returnFood/returnFoodOrder'
							},
						],
						// style:' width:330rpx;'
					},
					{
						title: '访客',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem29.png',
								text: '访客预约',
								// url:'/pages/componentsC/visitor/visitorForm',
								url:'/pages/componentsC/visitor/tempPersonList',
								
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem21.png',
								text: '预约记录',
								url:'/pages/componentsC/visitor/visitorRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem22.png',
								text: '访客记录',
								url:'/pages/componentsC/visitor/visitorRecord?isVisitor=2'
							},
						],
						// style:'width:330rpx;'
					},
					{
						title: '资产管理',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem23.png',
								text: '报修登记',
								url: ''
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem24.png',
								text: '报修记录',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem25.png',
								text: '报修任务分配',
								url: ''
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem26.png',
								text: '报修分配记录',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem27.png',
								text: '报修待处理',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem28.png',
								text: '报修处理记录',
								url:''
							},
						]
					},
					{
						title: '审批',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/teacherItem29.png',
								text: '待审核补登',
								url: '/pages/componentsC/checkingIn/auditRepairList'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem30.png',
								text: '待审核事件登记',
								url: '/pages/componentsC/checkingIn/auditEventRepairList'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem31.png',
								text: '历史补登审核',
								url: '/pages/componentsC/checkingIn/auditRepairList?isAudit=2'
							},
							{
								img: base.imgBaseUrl+'/images/work/teacherItem32.png',
								text: '历史登记审核',
								url: '/pages/componentsC/checkingIn/auditEventRepairList?isAudit=2'
							},
						]
					},
				],
				studentHandleArr:[
					{
						title: '请假',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item1.png',
								text: '学生请假',
								url: '/pages/componentsC/checkingIn/leaveRequest'
							},
							{
								img: base.imgBaseUrl+'/images/work/item2.png',
								text: '学生请假记录',
								url: '/pages/componentsC/checkingIn/leaveRecord'
							},
						]
					},
					{
						title: '消费',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item3.png',
								text: '充值',
								url:'/pages/componentsB/topupCard/topupCard'
							},
							{
								img: base.imgBaseUrl+'/images/work/item4.png',
								text: '充值记录',
								url: '/pages/componentsB/topupRecord/topupRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/item5.png',
								text: '消费记录',
								url:'/pages/componentsB/consumeRecord/consumeRecord'
							},
						]
					},
					{
						title: '安全',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item6.png',
								text: '出入记录',
								url:'/pages/componentsC/safe/accessRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/item7.png',
								text: '归寝记录',
								url:'/pages/componentsC/dorm/attendanceRecord'
							},
							{
								img: base.imgBaseUrl+'/images/work/item8.png',
								text: '学生轨迹',
								url:'/pages/componentsC/safe/studentTrack'
							},
							{
								img: base.imgBaseUrl+'/images/work/item20.png',
								text: '校车轨迹',
								url:'/pages/componentsC/safe/busTrack'
							},
						]
					},
					{
						title: '公话',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item9.png',
								text: '公话套餐',
								url:'/pages/componentsC/phone/phonePackage'
							},
							// {
							// 	img:'',
							// 	text: '话费充值',
							// 	url:'/pages/componentsC/phone/bugPackage'
							// },
							{
								img: base.imgBaseUrl+'/images/work/item10.png',
								text: '通话记录',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/item11.png',
								text: '互动留言',
								url:''
							},
						]
					},
					{
						title: '退餐',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item12.png',
								text: '退餐申请',
								url:'/pages/componentsC/returnFood/returnFood'
							},
							{
								img: base.imgBaseUrl+'/images/work/item13.png',
								text: '退餐记录',
								url:'/pages/componentsC/returnFood/returnFoodOrder'
							},
						],
						style:' width:330rpx;'
					},
					{
						title: '退课',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item14.png',
								text: '退课申请',
								url:'/pages/componentsC/dropClass/dropClass'
							},
							{
								img: base.imgBaseUrl+'/images/work/item15.png',
								text: '退课记录',
								url:'/pages/componentsC/dropClass/dropClassList'
							},
						],
						style:' width:330rpx;'
					},
					{
						title: '成绩',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item16.png',
								text: '最新成绩',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/item17.png',
								text: '历史成绩',
								url:''
							},
						],
						style:' width:330rpx;'
					},
					{
						title: '校服',
						pageArr:[
							{
								img: base.imgBaseUrl+'/images/work/item18.png',
								text: '校服订购',
								url:''
							},
							{
								img: base.imgBaseUrl+'/images/work/item19.png',
								text: '历史订购',
								url:''
							},
						],
						style:' width:330rpx;'
					},
					// {
					// 	title: '课程表',
					// },
					// {
					// 	title: '作业',
					// 	pageArr:[
					// 		{
					// 			img:'',
					// 			text: '今日作业',
					// 			url:''
					// 		},
					// 		{
					// 			img:'',
					// 			text: '作业记录',
					// 			url:''
					// 		},
					// 	]
					// },
					// {
					// 	title: '成绩',
					// },
				],
				handleArr : [],
				isTeacher: 1,
				pageItem,
				selectInfoAccount : {},
				merchArr:[[]],
				selectMerchShow: false,
				mobile: '',
				isFirstRegPhone: false,
			}
		},
		methods: {
			getMenu(){
				return sysAppletPermissionQueryByUserNameApi({
					userName : this.selectInfoAccount.code
				}).then(res=>{
					let data = res.result
					let menuArr = []
					data.forEach(item=>{
						if(item.menuType==0){
							menuArr.push(item)
						}
					})
					data.forEach(item=>{
						if(item.menuType==1){
							let tempIndex = menuArr.findIndex((item2)=>{return item.parentId==item2.id })
							if(!menuArr[tempIndex].pageArr){
								menuArr[tempIndex].pageArr = []
							}
							menuArr[tempIndex].pageArr.push(item)
						}
					})
					this.handleArr = menuArr
					console.log(this.handleArr);
				})
			},
			selectConfirm(e){
				console.log(e);
				let merchNo = e.value[0].id
				this.selectMerchShow = false
				this.goPage('/pages/componentsC/dingcanMan/dingcanMan',{
					merchNo
				})
			},
			getCountMoney(){
				return countAmtApi().then(res=>{
					this.countMoneyObj = res.data
				})
			},
			bindAccount(){
				uni.showModal({
					content: '暂未绑定账号信息，是否进行绑定',
					success: (res) => {
						if(res.confirm){
							this.goPage('/pages/componentsA/bingInfo/bingInfo')
						}
					}
				})
			},
			handleVisitorShare(){
				uni.share({
				    provider: 'weixin',
				    scene: "WXSceneSession",
				    type: 5,
				    imageUrl: '',
				    title: '访客邀请',
				    miniProgram: {
				        id: 'wx8e834822b86c7d4d',
				        path: '/pages/componentsC/visitor/visitorForm',
				        type: 0,
				        // webUrl: 'http://uniapp.dcloud.io'
				    },
				    success: ret => {
				        console.log(JSON.stringify(ret));
				    }
				});
			},
			handleGoPage(url,item){
				console.log(url);
				console.log(item);
				let info = uni.getStorageSync('selectInfoAccount')
				if(!info){
					this.bindAccount()
				}else{
					if(url=='/pages/componentsC/dingcanMan/dingcanMan'){
						this.selectMerchShow = true
					}else if(item.name == '访客邀请'){
						console.log('访客邀请');
						this.handleVisitorShare()
					}else if(item.name == '互动留言'){
						wx.navigateToMiniProgram({
							appId: 'wx2cfb61ccc8e0eb31',
							path:'/pages/login/login',
						　  envVersion: 'release',// 打开正式版
							extraData:{
							organization: '',
							mobile: this.mobile ? this.mobile : '',   // 登录号码
							jump2Type: 3,           // 1.学生列表 2.授权列表 3.留言列表
							},
							// envVersion:"trial"  // trial 体验版 正式版不需要加上
						})
					}else if(item.name == '公话套餐' && this.isFirstRegPhone){
						this.goPage('/pages/componentsC/phone/phoneFace')
					}else{
						this.goPage(url)
					}
				}
			},
			getTel: function () {
				let data = {
					usid: this.selectInfoAccount.id,
					// usid: '1771107644199706625',
					// xxbm: this.selectInfoAccount.departmentId,
					xxbm: this.xxbm,
				}
				return getParentApi(data).then(res=>{
					if(res.model){
						if(res.model.mobile){
							this.mobile = res.model.mobile
						}
						if(!res.model.name){
							this.isFirstRegPhone = true
							uni.setStorageSync('isFirstRegPhone',true)
						}else{
							this.isFirstRegPhone = false
							uni.setStorageSync('isFirstRegPhone',false)
						}
					}else{
						this.isFirstRegPhone = true
						uni.setStorageSync('isFirstRegPhone',true)
					}
				})
			},
			getRemberInfo(){
				let selectInfoAccount = uni.getStorageSync('selectInfoAccount')
				return getPersonApi({
					personId : selectInfoAccount.id ? selectInfoAccount.id : ''
				}).then(res=>{
					console.log(res);
					if(res.result.tenantList && res.result.tenantList.length){
						let id = res.result.tenantList[0].id
						uni.setStorageSync('X-Tenant-Id',id)
					}
					this.selectInfoAccount = res.result.personList[0]
					this.isTeacher = 2
					if(this.selectInfoAccount.positionList && this.selectInfoAccount.positionList.length){
						this.selectInfoAccount.positionList.forEach(item=>{
							if(item.managerType==1){
								this.isTeacher = 1 
							}
						})
					}
					// if(this.selectInfoAccount.departName=='教职工'){
					// 	this.isTeacher = 1 
					// } else{
					// 	this.isTeacher = 2
					// }
					// if(this.isTeacher==1){
					// 	this.handleArr = this.teacherHandleArr
					// }else if(this.isTeacher==2){
					// 	this.handleArr = this.studentHandleArr
					// }
					uni.setStorageSync('isTeacher',this.isTeacher)
					uni.setStorageSync('selectInfoAccount',this.selectInfoAccount)
					uni.setStorageSync('token',res.result.token)
					
					// this.getMenu()
				}).catch(err=>{
					console.log(err);
					if(err.code==500 && err.message == '该微信没有绑定'){
						this.bindAccount()
					}
				})
			},
			initCode(){
				getCodeIndexApi().then(res=>{
					
				})
			}
			
		},
		filters:{
			handleText(val){
				let text = ''
				menuList.forEach(item=>{
					if(item.label == val){
						text = item.text
					}
				})
				return text
			}
		},
		async onLoad({code}) {
			// this.initCode()
			console.log(code);
			if(code){
				await getoaOpenInfoApi({code}).then(res=>{
					 uni.setStorageSync('oaopenid',res.result.oaopenid)
				})
			}
			// #ifdef MP-WEIXIN
			if(!uni.getStorageSync('oaopenid')){
				uni.reLaunch({
					url: '/pages/index/webview'
				})
			}
			// #endif
			// #ifdef H5
			if(!uni.getStorageSync('oaopenid')){
				uni.reLaunch({
					url: '/pages/index/h5Webview'
				})
			}
			// #endif
			menuList = this.language.menuList
			// this.menuList = this.language.menuList
			let tabbar = this.language.tabbar
			uni.setTabBarItem({
				index: 0,
				text: tabbar.item1,
			})
			uni.setTabBarItem({
				index: 1,
				text: tabbar.item2,
			})
			uni.setTabBarItem({
				index: 2,
				text: tabbar.item3,
			})
			// if(this.isTeacher==1){
			// 	this.handleArr = this.teacherHandleArr
			// }else if(this.isTeacher==2){
			// 	this.handleArr = this.studentHandleArr
			// }
		},
		async onShow() {
			uni.setStorageSync('uniformShopIndex',0)
			this.setPageTitle(this.language.index.title)
			await this.getRemberInfo()
			await this.getMenu()
			// #ifdef MP-WEIXIN
			await this.getTel()
			// #endif
		},
	}
</script>

<style lang="scss" scoped>
		.handleBox{
			width: 690rpx;
			background: #FFFFFF;
			box-shadow: 0px 0px 20px 0px rgba(102, 102, 102, 0.05);
			// margin: 30rpx auto 0;
			margin-top: 30rpx;
			// margin-left: 30rpx;
			border-radius: 20rpx;
			.handleTitle{
					padding: 20rpx 30rpx;
					color: #333;
					font-weight: 600;
					position: relative;
					font-size: 32rpx;
					&::after{
						content: '';
						position: absolute;
						top: 50%;
						left: 14rpx;
						transform: translateY(-50%);
						width: 8rpx;
						height: 30rpx;
						// background: #4089f0;
						background: linear-gradient(to bottom, #00d973, #087dde);
						border-radius: 4rpx;
					}
			}
		
			.handleArr{
				display: flex;
				// justify-content: space-evenly;
				flex-wrap: wrap;
				.handleItem{
					// padding-bottom: 30rpx;
					width: 165rpx;
					// width: 25%;
					// min-height: 180rpx;
					@include flexColCenter;
					padding: 0 10rpx 30rpx ;
					.cover{
						width: 99rpx;
						height: 99rpx;
						@include flexCenter;
						image{
							
						}
						
					}
					text{
						margin-top: 20rpx;
						color: #333;
						font-size: 24rpx;
					}
					
					
				}
			}
		}
	
	
	.workContent{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-evenly;
	}
.leftRightRow{
	width: 690rpx;
	display: flex;
	justify-content: space-between;
	margin: 30rpx auto 0;
	.leftRightItem{
		width: 48%;
		height: 140rpx;
		display: flex;
		align-items: center;
		background: #FFFFFF;
		box-shadow: 0px 0px 20px 0px rgba(102, 102, 102, 0.05);
		border-radius: 20rpx;
		padding-left: 40rpx;
		text{
			margin-left: 30rpx;
		}
	}
}
	
.page{
	padding-bottom: 50rpx;
	
	
	
	
}
</style>
